---
title: "Bootstrap"
author: "`r Sys.info()['user']`"
date: "`r format(Sys.time(), '%Y-%m-%d')`"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width = 10, fig.height = 5)
source("functions.R")
```

```{r}
dat_ja <- readRDS("data_bootstrap_ja.RDS")
t <- dat_ja$t[dat_ja$window == 60]
quantile(t, c(0.95, 0.99, 0.999), na.rm = TRUE)
sum(t >= 0.258 / 0.126, na.rm = TRUE) / length(t)
```

```{r}
dat_he <- readRDS("data_bootstrap_he.RDS")
t <- dat_he$t[dat_he$window == 30]
quantile(t, c(0.95, 0.99, 0.999), na.rm = TRUE)
sum(t >= 0.349 / 0.156, na.rm = TRUE) / length(t)
```


```{r fig.height=4, fig.width=10}
par(mfrow = c(1, 2))
plot(density(subset(dat_ja, window == 30)$t, na.rm = TRUE), col = color[1], lwd = 2,
     main = "Japan", font.main = 1, ylim = c(0, 0.4), xlab = "")
lines(density(subset(dat_ja, window == 60)$t, na.rm = TRUE), col = color[2], lwd = 2)
lines(density(subset(dat_ja, window == 90)$t, na.rm = TRUE), col = color[3], lwd = 2)
legend("topright", c("30", "60", "90"), col = color[1:3], lty = 1, lwd = 2)

plot(density(subset(dat_he, window == 30)$t, na.rm = TRUE), col = color[1], lwd = 2,
     main = "Israel", font.main = 1, ylim = c(0, 0.4), xlab = "")
lines(density(subset(dat_he, window == 60)$t, na.rm = TRUE), col = color[2], lwd = 2)
lines(density(subset(dat_he, window == 90)$t, na.rm = TRUE), col = color[3], lwd = 2)
legend("topright", c("30", "60", "90"), col = color[1:3], lty = 1, lwd = 2)
par(mfrow = c(1, 1))
```
